//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.wangyadong.hobby.common.utils;




import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateUtils {
    public static final String DATE_FORMAT = "yyyy-MM-dd";
    public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_FORMAT_New = "yyyy年MM月dd日";
    public static final String DATETIME_FORMAT_WITH_POINT = "yyyy-MM-dd.HH:mm:ss";
    public static final String DATETIME_FORMAT_WITH_POINT_Z = "yyyy-MM-dd.HH:mm:ss z";
    public static final String MONTH_FORMAT = "yyyy-MM";
    public static final String MINITUE_FORMAT = "yyyy-MM-dd HH:mm";

    public DateUtils() {
    }

    public static String dateToString(Date date) {
        return dateToString(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String dateToString(Date date, String format) {
        if (date != null && format != null) {
            SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(format);
            return localSimpleDateFormat.format(date);
        } else {
            return null;
        }
    }



    public static Date stringToDate(String dateStr) {
        return stringToDate(dateStr, "yyyy-MM-dd");
    }


    public static Date stringToDate(String dateStr, String format) {
        Date localDate = null;
        if (dateStr != null && format != null) {
            try {
                SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(format);
                localDate = localSimpleDateFormat.parse(dateStr);
            } catch (ParseException var4) {
                var4.printStackTrace();
                localDate = null;
            }
        }

        return localDate;
    }





    public static int getMinuteBetween(Date date1, Date date2) {
        Long minuteLong = (date2.getTime() - date1.getTime()) / 60000L + 1L;
        if (minuteLong.longValue() < 0L) {
            minuteLong = -minuteLong.longValue();
        }

        return minuteLong.intValue();
    }











    public static Date decMinute(Date date, int offset) {
        Calendar localCalendar = Calendar.getInstance();
        localCalendar.setTime(date);
        localCalendar.add(12, 0 - offset);
        return localCalendar.getTime();
    }





    public static Date toZoneDay(Date date, int hour) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(1);
        int month = calendar.get(2);
        int day = calendar.get(5);
        calendar.set(year, month, day, hour, 0, 0);
        calendar.set(14, 0);
        Date newDate = calendar.getTime();
        return newDate;
    }



    public static void main(String[] args) {
        System.out.println(getMinuteBetween(decMinute(new Date(), -10), new Date()));
        System.out.println(new Date());
        System.out.println(decMinute(new Date(), -10));
    }




    public static Date getDateAfter(int day) {
        Calendar now = Calendar.getInstance();
        now.set(5, now.get(5) + day);
        return now.getTime();
    }



    public static class ContestDate {
        public static int ACCOUNT_DAY = 7;
        public static int DAYS_OF_ACCOUNT_CYCLE = 7;
        public static int ACCOUNT_HOUR = 20;
        public static int ACCOUNT_VOTE_HOUR = 0;
        public int year;
        public int month;
        public int week;
        public int weekCount;
        public Date date;
        public Date weekVoteStart;
        public Date weekStart;
        public Date weekEnd;
        public Date monthStart;
        public Date monthEnd;

        private ContestDate() {
        }

        private ContestDate(Date theDate) {
            if (theDate == null) {
                theDate = new Date();
            }

            this.date = theDate;
            Calendar calendar = Calendar.getInstance();
            theDate = DateUtils.toZoneDay(theDate, ACCOUNT_HOUR);
            if (this.date.before(theDate)) {
                calendar.setTime(theDate);
                calendar.add(6, -1);
                theDate = calendar.getTime();
            } else {
                calendar.setTime(theDate);
            }

            calendar.set(7, ACCOUNT_DAY);
            this.weekStart = calendar.getTime();
            if (theDate.before(this.weekStart)) {
                this.weekEnd = this.weekStart;
                calendar.add(6, -DAYS_OF_ACCOUNT_CYCLE);
                this.weekStart = calendar.getTime();
            } else {
                calendar.add(6, DAYS_OF_ACCOUNT_CYCLE);
                this.weekEnd = calendar.getTime();
            }

            this.weekVoteStart = DateUtils.toZoneDay(this.weekStart, ACCOUNT_VOTE_HOUR);
            calendar.setTime(this.weekStart);
            this.year = calendar.get(1);
            this.month = calendar.get(2);
            this.week = calendar.get(4);
            calendar.add(6, -DAYS_OF_ACCOUNT_CYCLE * this.week);
            this.monthStart = calendar.getTime();
            this.weekCount = this.week;
            this.monthEnd = this.weekEnd;
            calendar.setTime(this.weekEnd);

            while(this.month == calendar.get(2)) {
                calendar.add(6, DAYS_OF_ACCOUNT_CYCLE);
                this.monthEnd = calendar.getTime();
                ++this.weekCount;
            }

        }



        public String toString() {
            return "\nyear:" + this.year + "\nmonth:" + this.month + "\n" + "week:" + this.week + "\nweekCount:" + this.weekCount + "\n" + "date:" + DateUtils.dateToString(this.date) + "\nweekStart:" + DateUtils.dateToString(this.weekStart) + "\nweekEnd:" + DateUtils.dateToString(this.weekEnd) + "\n" + "weekVoteStart:" + DateUtils.dateToString(this.weekVoteStart) + "\n" + "monthStart:" + DateUtils.dateToString(this.monthStart) + "\nmonthEnd:" + DateUtils.dateToString(this.monthEnd);
        }

        public static void main(String[] args) {
            System.out.println(DateUtils.getDateAfter(30));
        }
    }
}
